/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package jsalon.web.controller;

import jamjun.infra.annotation.Param;
import jamjun.infra.model.UserSession;
import static jamjun.infra.web.CHelper.MappingRequestToObj;
import jamjun.infra.web.Content;
import jamjun.infra.web.Controller;
import jamjun.infra.web.GSession;
import jamjun.infra.web.Json;
import jamjun.infra.web.Result;
import jamjun.infra.web.View;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.annotation.WebServlet;
import jsalon.repo.UserSessionRepo;
import jsalon.web.vm.HomeViewModel;
import jsalon.web.vm.MenuViewModel;

/**
 *
 * @author Java
 */
@WebServlet(name = "home", urlPatterns = {"/home"})
public class HomeController extends Controller {
    public static Result index() 
    {
        try 
        {
            GSession.setLocale();
            HomeViewModel viewModel = new HomeViewModel();
            UserSessionRepo userSessionRepo = new UserSessionRepo();
            String sessionID = "abc";
            UserSession userSession;
            try {
                userSession = userSessionRepo.getFirst(sessionID);
                GSession.setUserSession(userSession);
                GSession.setCookieSession("jslonSessionID",sessionID);
                GSession.setCookieSession("jslonDomainID",userSession.domainID);
            } catch (Exception ex) {
                Logger.getLogger(CustomerController.class.getName()).log(Level.SEVERE, null, ex);
            }
            return new View("/View/Home/index.jsp",viewModel);
        } catch (Exception ex) {
            Logger.getLogger(CustomerController.class.getName()).log(Level.SEVERE, null, ex);
            return new Content(ex.getMessage());
        }        
        
    }
    
    public static Result menu(@Param(name="data") String menuActive)
    {
        //<editor-fold desc="parameter">
        
        //</editor-fold>
        //<editor-fold desc="code">
        
        //</editor-fold>
        List<MenuViewModel> dataList = new ArrayList<MenuViewModel>();
        MenuViewModel data = new MenuViewModel();
        data.id="0";
        data.caption = "ข้อมูลลูกค้า";
        data.isVisible = "true";
        data.link = "[redirect]customer?[ac]=index&menuID="+data.id;
        data.menuActive = "";
        dataList.add(data);
        data = new MenuViewModel();
        data.id="1";
        data.caption = "สินค้าและบริการ";
        data.isVisible = "true";
        data.link = "[redirect]product?[ac]=index&menuID="+data.id;
        data.menuActive = "";
        dataList.add(data);
        data = new MenuViewModel();
        data.id="2";
        data.caption = "ข้อมูลค่าใช้จ่าย";
        data.isVisible = "true";
        data.link = "[redirect]product?[ac]=index&menuID="+data.id;
        data.menuActive = "";
        dataList.add(data);
        data = new MenuViewModel();
        data.id="3";
        data.caption = "นัดหมาย";
        data.isVisible = "true";
        data.link = "[redirect]product?[ac]=index";
        data.menuActive = "";
        dataList.add(data);
        return new Json(dataList);
    }
}
